<?php
namespace app\index\controller;
use think\Controller;

class Upload extends Index
{
    public function index()
    {
        $path = 'static/images';
        $file = request()->file('image');
        if($file){
            // 移动到框架应用根目录/public/uploads/ 目录下
            $info = $file->validate(['size'=>20*1024*1024,'ext'=>'jpg,png,jpeg'])->move($path);
            if($info){
                $res = [
                    'name' => $_FILES['image']['name'],
                    'primitive_name' => $_FILES['image']['name'],
                    'size' => $info->getSize(),
                    'url' => $path . DS . $info->getSaveName()
                ];
                $data = $res;
                $data['path'] = $path . DS . $info->getSaveName();
                $data['create_time'] = $data['update_time'] = date('Y-m-d H:i:s');
                return ajax_return(200,'file upload success', $res , false);
            }else{
                // 上传失败获取错误信息
                return ajax_return(304);
            }
        }
        return ajax_return(303);
    }
}
